#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/2/5 11:41
# @Author  : Ramsey
# @Site    : zh
# @File    : status_collector.py
# @Software: PyCharm
from pprint import pformat
from typing import Final
from spider_framework.utils.log import spider_logger


class StatusCollector:

    def __init__(self, crawler):
        self.status_dict: dict = dict()
        self.crawler = crawler
        self.logger = spider_logger(name=self.__class__.__name__, log_level="INFO")

    def increase_value(self, key: str, count: int = 1, start: int = 0):
        self.status_dict[key] = self.status_dict.setdefault(key, start) + count

    def get_status_dict(self):
        return self.status_dict

    def set_status_dict(self, status_dict: dict):
        self.status_dict = status_dict

    def clean_status_dict(self):
        self.status_dict = dict()

    def close_spider(self, spider, reason):
        self.status_dict["reason"] = reason
        self.logger.info(f"{spider} status: \n" + pformat(self.status_dict))


if __name__ == "__main__":
    pass
